package com.lbx;

import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

import static com.alibaba.fastjson.JSON.toJSONString;

/**
 * @author lbx create by 2021/6/8 14:26
 * @apiNote MyController
 */
@Controller
public class MyController {
    @GetMapping({"/", "/index"})
    public String goIndex(HttpServletRequest request, Model model){
        String token = request.getParameter("token");
        if (token!=null){
            model.addAttribute("token",token);
            model.addAttribute("loginUser",request.getSession().getAttribute("loginUser"));
            System.err.println("user"+request.getSession().getAttribute("loginUser"));
        }
        return "index";
    }
    
    @GetMapping("/goView/{view}")
    public String goView(@PathVariable String view){
        return view;
    }
    
    @ResponseBody
    @GetMapping("/test")
    public String test(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("status",200);
        map.put("message","success");
        map.put("data",123456);
        return toJSONString(map);
    }
}
